<template>
	<view class="container">
		<view class="title align-center justify-center">
			
	
		</view>

		<view class="box">
			<view class="tabs mb20 align-center justify-between">
				<view :class="act==0?'active':''" @click="act=0">
				 合格证查询
				</view>

			</view>
			<view class="plr15 mt50">
				<uv-input  placeholder="请输入报告编号" clearable border="surround" v-model="value1"></uv-input>
				
				<uv-input @clear="clear" class="mt20 mb20" placeholder="请输入样品编码" clearable border="surround" v-model="value"></uv-input>
			<uv-button @click="submit" class="mt20" text="查询" color="#4375f2"></uv-button>
			
			<view class="ft20 mt20" v-if="dataList.length">
				合格证列表
			</view>
				<view v-if="dataList.length" class="report">
				
					<view class="justify-between align-center reportList " v-for="(i,n) in dataList" :key="n" @click="toMain(i)">
						<text>报告编号：{{i.reportNum}}</text> <view style="color: #999;" class="align-center">查看详情<uv-icon name="arrow-right" ></uv-icon>
							
						</view> 
					</view>
				</view>	
			
			
			</view>

		</view>
	</view>
</template>

<script>
	import CryptoJS from "crypto-js";

	let app = getApp();
	export default {
		components: {

		},
		data() {
			return {
				act: 0,
				dataInfo: {},
				certificateNum: '',
				value: "",
				value1:"",
				dataList:[]
			}
		},
		onLoad(opt) {
document.title= '方圆检测认证集团有限公司'
		},
		mounted() {


		},

		methods: {

			CryptoJSData(data) {
				let encryptedHexStr = CryptoJS.enc.Utf8.parse(data);

				// 密钥，应该是一个16位、24位或32位的字符串，对应AES-128、AES-192或AES-256
				const key = CryptoJS.enc.Utf8.parse("fyjcrzjtyxgsjcbg");

				// 选择加密模式，这里使用CBC模式
				const iv = CryptoJS.enc.Utf8.parse("fyjcrzjtyxgsjcbg"); // 初始化向量

				// 加密
				let encrypted = CryptoJS.AES.encrypt(data, key, {
					iv: iv,
					mode: CryptoJS.mode.CBC,
					padding: CryptoJS.pad.Pkcs7,
				});
				return encrypted.toString();
			},
			toMain(i){
				let num = this.CryptoJSData(i.number)
				let nums=this.CryptoJSData(i.reportNum)
				console.log(num,nums)
				uni.navigateTo({
					url:'/pages/index/index?certificateNum='+encodeURIComponent(num) +'&reportNum='+encodeURIComponent(nums),
				})
			},
			clear(){
				this.dataList = []
			},
			submit() {
				if (!this.value) return uni.showToast({
					title: '请输入样品编码',
					icon: 'none'
				})
				let vm =this
				let num = this.CryptoJSData(this.value)
				let nums=''
			if(this.value1){
				nums = this.CryptoJSData(this.value1)
			}	uni.showLoading({
				title:'加载中'
			})
				vm.dataList = []
				uni.request({
					url:'http://129.211.213.130:8090/api/report/certificateQrDetail?certificateNum='+encodeURIComponent(num) +'&reportNum='+encodeURIComponent(nums),
					method:'GET',
					success:function(res){
							uni.hideLoading()
							if(res.data.data){
								if(res.data.data.list&&res.data.data.list.length==1){
									uni.navigateTo({
										url:'/pages/index/index?certificateNum='+encodeURIComponent(num) +'&reportNum='+encodeURIComponent(nums),
									})
								}else if(res.data.data.list.length>1){
										vm.dataList = res.data.data.list
								}else{
									uni.showToast({
										title:'信息不存在,请核对编号！',
										icon:'none'
									})
								}
							}else{
								uni.showToast({
									title:res.data.message,
									icon:'none'
								})
							}
							
					},fail:function(err){
						console.log(err)
						uni.hideLoading()
					}
				})
				
			}
		}





	}
</script>
<style scoped lang="scss">
	.container {
		height: 100vh;
		background: linear-gradient(180deg, #4375f2, #fff);
		padding-top: 40rpx;
	}

	.title {

		text-align: center;
		color: #fff;
		font-size: 42rpx;
		font-weight: 600;
		line-height: 42rpx;
		image{
			width: 100rpx;
		}

	}

	.box {
		margin: 40rpx;
		background-color: #fff;
		padding-bottom: 30rpx;
		border-radius: 12rpx;

	}

	.tabs {


		view {
			flex: 1;
			height: 100rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 40rpx;
		}

		.active {
			background: #4375f2;
			color: #fff;
			border-radius: 12rpx 0 0 0;
		}
	}

	table {
		margin: 30rpx 30rpx 0;
	}

	td {
		height: 120rpx;
		font-size: 28rpx;
		width: 200rpx;
		padding: 30rpx;
		font-weight: 700;
		border-top: 1px solid #cad9fe;
		box-sizing: border-box;
		border-right: 1px solid #cad9fe
	}

	.t {

		background: #f7f9fe;
		border-left: 1px solid #cad9fe;
		text-align: center;
	}

	.contnet {
		color: #999;
		font-size: 30rpx;
		line-height: 40rpx;
	}

	.labelTitle {
		font-size: 32rpx;
		color: #000;
		margin-bottom: 20rpx;
		font-weight: 700;
	}
	.reportList{
		height: 100rpx;
		// border-bottom:2rpx solid #4375f2;
		border-radius: 12rpx;
	}
	.report{
		height: 500rpx;
		// overflow-y: scroll;
	}
</style>